angular.module('vote').controller('voteSeeCtrl', ['$scope', '$uibModalInstance', '$http', 'id', function ($scope, $uibModalInstance, $http, id) {
    $scope.vote = {};
    $scope.onInit = function () {
        if (id)
            $http.get(ctx + '/vote/detail/' + id).then(function (resp) {
                console.log(resp);
                $scope.vote = resp.data;
                for (var i = 0; i < $scope.vote.questions.length; i++) {
                    var question = $scope.vote.questions[i];
                    var amount = 0;
                    for (var j = 0; j < question.options.length; j++) {
                        var option = question.options[j];
                        amount += option.amount;
                    }
                    for (var j = 0; j < question.options.length; j++) {
                        var option = question.options[j];
                        option.percentage = amount == 0 ? '0%' : (((option.amount / amount) * 100) + '%');
                    }
                }

            });
    }
    $scope.onInit();

    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };
}]);